package com.hyy.libray.baselibrary;

import android.app.Application;
import android.content.Context;

import com.hyy.libray.ui.view.LottieEmpyCallback;
import com.hyy.libray.ui.view.LottieLoadingCallback;
import com.kingja.loadsir.callback.SuccessCallback;
import com.kingja.loadsir.core.LoadSir;


/**
 * @ClassName: com.yyh.baselibrary
 * @Description:
 * @Author: hyy
 * @Date: 2020/4/13
 * @Time: 4:39 PM
 */
public class BaseApplication {

    private Application application;

    private static BaseApplication baseApplication;

    /**
     * 初始化 BaseApplication
     *
     * @param application
     */
    public void init(Application application) {
        this.application = application;
    }

    public BaseApplication() {
        initLoadSir();
    }

    public static BaseApplication getInstance() {
        if (baseApplication == null) {
            synchronized (BaseApplication.class) {
                if (baseApplication == null) {
                    baseApplication = new BaseApplication();
                }
            }
        }
        return baseApplication;
    }

    public Context getContext() {
        return application.getBaseContext();
    }

    private void initLoadSir() {
        LoadSir.beginBuilder()
                .addCallback(new LottieLoadingCallback())
                .addCallback(new LottieEmpyCallback())
                .setDefaultCallback(SuccessCallback.class)
                .commit();
    }
}
